﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace GetAllProc
{
    class Program
    {
        static void Main(string[] args)
        {
            TestGetFiles();
        }

        public static void TestGetFiles()
        {
            string dir = @"C:\Windows\System32\spool";
            string[] strArray = System.IO.Directory.GetFiles(dir);
            foreach (string str in strArray)
            {
                Console.WriteLine(str);
            }
        }

        public static void TestProcInfo()
        {
            Process proc = Process.GetCurrentProcess();
            string filePath = proc.MainModule.FileName;
            string curPath = System.Environment.CurrentDirectory;
            Console.WriteLine(filePath);
            Console.WriteLine(curPath);

            int n = filePath.IndexOf("zzz");
            Console.WriteLine(n);
        }

        public static void GetAllProcess(string[] args)
        {
            Process[] procArray;
            if (args.Length==1)
            {
                foreach (string str in args)
                {
                    Console.WriteLine("======================="+str);
                    procArray = Process.GetProcessesByName(str);
                    foreach (Process p in procArray)
                    {
                        Console.WriteLine(p.MainModule.FileName);
                    }
                }
            }
            else if (args.Length==0)
            {
                procArray = Process.GetProcesses();
                foreach (Process p in procArray)
                {
                    Console.WriteLine(p.MainModule.FileName);
                }
            }
            
            Console.WriteLine("==========================");
        }
    }
}
